const moment = require('../libs/moment')
// const _moment = moment()

function formatArg(arg) {
  let temp = []
  for (let key in arg) {
    let value = arg[key]
    if (value != 'string' || value != 'number') {
      value = JSON.stringify(value)
    }
    temp.push(value)
  }
  return temp
}

const main = {
  head: [],
  body: [],
  writeHead() {
    let temp = formatArg(arguments)
    main.head.push(`${moment().format("YYYY-MM-DD H:mm:ss")} ${temp.join(' ')}`)
  },
  writeBody() {
    let temp = formatArg(arguments)
    main.body.push(`${moment().format("YYYY-MM-DD H:mm:ss")} ${temp.join(' ')}`)
  },
  result() {
    let str = ''
    str += main.head.join('\r\n')
    str += '\r\n'
    str += main.body.join('\r\n')

    return str
  },
  clear() {
    main.head = []
    main.clearBody()
  },
  clearBody() {
    main.body = []
  }
}

module.exports = main
